package com.smarttourism.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.smarttourism.common.core.domain.R;
import com.smarttourism.domain.Bill;
import com.smarttourism.domain.Room;
import com.smarttourism.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bill")
public class BillController {
    @Autowired
    private BillService billService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('bill:bill:list')")
    public R findAllBill(String pname,String billNum,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Bill> list = billService.findAll(pname,billNum);
        PageInfo<Bill> roomPageInfo = new PageInfo<>(list);
        return roomPageInfo != null?R.ok(roomPageInfo):R.fail("查询失败");
    }
    @PostMapping("/add")
    @PreAuthorize("@ss.hasPermi('bill:bill:list')")
    public R addBill(@RequestBody Bill bill){
        int i = billService.add(bill);
        return i>0?R.ok("新增成功"):R.fail("新增失败");

    }
    @DeleteMapping
    @PreAuthorize("@ss.hasPermi('bill:bill:list')")
    public R deleteBatch(Integer[] ids){
        int i = billService.removeBatch(ids);
        return i>0?R.ok("删除成功"):R.fail("删除失败");
    }
}
